<template>
    <a-card :bordered="false">

        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
            <a-form layout="inline" @keyup.enter.native="searchQuery">
                <a-row :gutter="24">
                    <a-col :xl="6" :md="8" :sm="16">
                        <a-form-item label="消息标题">
                            <a-input placeholder="请输入消息标题" v-model="queryParam.msgTitle"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :xl="6" :md="8" :sm="16">
                        <a-form-item label="状态">
                            <j-dict-select-tag v-model="queryParam.msgStatus" placeholder="请选择状态"
                                dictCode="msgStatus" />
                        </a-form-item>
                    </a-col>
                    <a-col :xl="6" :md="8" :sm="16">
                        <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                            <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                            <a-button @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
                            <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                                {{ toggleSearchStatus ? '收起' : '展开' }}
                                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
                            </a> -->
                        </span>
                    </a-col>
                </a-row>
            </a-form>
        </div>

        <!-- 操作按钮区域 -->
        <!-- 修改、审核、删除、撤销审核 -->
        <div class="table-operator">
            <a-button @click="handleAdd" v-has="'msgNotice:edit'" type="primary" icon="plus">新增</a-button>
            <!-- <a-button type="primary" icon="download" @click="handleExportXls('消息通知')">导出</a-button> -->
            <a-dropdown v-if="selectedRowKeys.length > 0">
                <a-menu slot="overlay">
                    <a-menu-item key="1" @click="batchDel">
                        <a-icon type="delete" />
                        删除
                    </a-menu-item>
                </a-menu>
                <a-button style="margin-left: 8px"> 批量操作
                    <a-icon type="down" />
                </a-button>
            </a-dropdown>
        </div>

        <!-- table区域-begin -->
        <div>
            <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
                <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
                    selectedRowKeys.length }}</a>项
                <a style="margin-left: 24px" @click="onClearSelected">清空</a>
            </div>

            <a-table ref="table" size="middle" bordered rowKey="id" :columns="columns" :dataSource="dataSource"
                :pagination="ipagination" :loading="loading" class="j-table-force-nowrap"
                :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
                @change="handleTableChange">
                <!-- 未审核 可以修改审核删除   已审核 撤销审核 -->
                <span slot="action" slot-scope="text, record">
                    <a-button type="link" @click="handleDetail(record)" style="padding: 2px;">详情</a-button>

                    <a-button type="link" v-if="record.msgStatus == 0" v-has="'msgNotice:edit'"
                        @click="handleEdit(record)" style="padding:0 2px;">编辑</a-button>

                    <a-button type="link" v-if="record.msgStatus == 0" v-has="'msgNotice:approve'"
                        @click="handleAudit(record)" style="padding:0 2px;">审核</a-button>

                    <a-popconfirm title="确定撤销审核吗?" v-if="record.msgStatus == 1" placement="topLeft"
                        v-has="'msgNotice:cancelApprove'" @confirm="() => handleUnAudit(record.id)">
                        <a-button type="link" style="padding:0 2px;">撤销审核</a-button>
                    </a-popconfirm>

                    <a-popconfirm title="确定删除吗?" v-if="record.msgStatus == 0" placement="topLeft"
                        v-has="'msgNotice:delete'" @confirm="() => handleDelete(record.id)">
                        <a-button type="link" style="color: red;padding:0 2px;">删除</a-button>
                    </a-popconfirm>
                </span>

            </a-table>
        </div>
        <!-- table区域-end -->

        <!-- 表单区域 -->
        <sysMsgNotice-modal ref="modalForm" @ok="modalFormOk"></sysMsgNotice-modal>
    </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less';
import SysMsgNoticeModal from './modules/SysMsgNoticeModal';
import { JeecgListMixin } from '@/mixins/JeecgListMixin';
import { getAction } from '@/api/manage';

export default {
    name: "SysMsgNoticeList",
    mixins: [JeecgListMixin],
    components: {
        SysMsgNoticeModal
    },
    data() {
        return {
            description: '消息通知管理页面',
            // 表头
            columns: [
                {
                    title: '#',
                    dataIndex: '',
                    key: 'rowIndex',
                    width: 60,
                    align: "center",
                    customRender: function (t, r, index) {
                        return parseInt(index) + 1;
                    }
                },
                {
                    title: '消息标题',
                    align: "center",
                    dataIndex: 'msgTitle'
                },
                {
                    title: '创建人',
                    align: "center",
                    dataIndex: 'createBy'
                },
                {
                    title: '创建时间',
                    align: "center",
                    dataIndex: 'createTime'
                },
                {
                    title: '审核人',
                    align: "center",
                    dataIndex: 'auditBy'
                },
                {
                    title: '审核时间',
                    align: "center",
                    dataIndex: 'auditTime'
                },
                {
                    title: '状态',
                    align: "center",
                    dataIndex: 'msgStatus_dictText'
                },
                {
                    title: '操作',
                    dataIndex: 'action',
                    align: "center",
                    scopedSlots: { customRender: 'action' },
                }
            ],
            url: {
                list: "/system/sysMsgNotice/list",
                delete: "/system/sysMsgNotice/delete",
                deleteBatch: "/system/sysMsgNotice/deleteBatch",
                exportXlsUrl: "system/sysMsgNotice/exportXls",
                importExcelUrl: "system/sysMsgNotice/importExcel",
                audit: "system/sysMsgNotice/audit",
                unAudit: '/system/sysMsgNotice/unAudit'
            },
        }
    },
    computed: {
        importExcelUrl: function () {
            return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
        }
    },
    methods: {
        handleAudit(record) {
            this.$refs.modalForm.edit(record, 1);
            this.$refs.modalForm.title = "审核";
            this.$refs.modalForm.disableSubmit = false;
            return;
        },
        handleUnAudit(id) {
            if (!this.url.unAudit) {
                this.$message.error("请设置url.unAudit属性!")
                return
            }
            getAction(this.url.unAudit, { id }).then((res) => {
                if (res.success) {
                    this.$message.success(res.message);
                    this.loadData();
                } else {
                    this.$message.warning(res.message);
                }
            });
        },
    }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>